#include <iostream>
#include "../include/server.hpp"

void OnClosed(const Muduo::PtrConnection& conn)
{
    LOGDEBUG("close connection:%p", conn.get());
}
void OnConnected(const Muduo::PtrConnection& conn)
{
    LOGDEBUG("new connection: %p", conn.get());
}
void OnMessage(const Muduo::PtrConnection& conn, Muduo::Buffer* buf)
{
    buf->MoveReadOffest(buf->ReadAbleSize());
    std::string str = "hello client!";
    conn->Send(str.c_str(), str.size());
}

int main()
{
    Muduo::TcpServer svr(8888);
    svr.SetThreadCount(2);
    svr.EnableInactiveRelease(10);
    //设置用户提供的回调函数
    // SetCloseCallback函数的形参类型是和OnClosed函数指针类型的参数匹配的所以不需要用bind进行适配绑定
    //svr.SetCloseCallback(std::bind(OnClosed, std::placeholders::_1)); 
    svr.SetCloseCallback(OnClosed);
    svr.SetConnectedCallback(OnConnected);
    svr.SetMessageCallback(OnMessage);
    //启动服务器
    svr.Start();
    return 0;
}